<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="input">
    <script>
        var arr = [];
        var searchs =  [{
                spell: 'A',
                citys: [
                    {
                        name: "阿里",
                        id: 1001
                    },
                    {
                        name: "阿拉",
                        id: 1001
                    },
                    {
                        name: "阿克",
                        id: 1001
                    }

                ]

            },
            {
                spell: 'T',
                citys: [

                    {
                        name: "天天",
                        id: 2001
                    },
                    {
                        name: "天下",
                        id: 2002
                    },
                    {
                        name: "天里",
                        id: 2003
                    }

                ]
            }
        ]
        var input = document.getElementById('input');
        input.onkeydown = function(event){
            if(event.keyCode == 13){
                if(this.value!=''){
                    var keyword = this.value;
                    for(var i =0 ;i<searchs.length;i++){
                        var citys = searchs[i].citys;
                        for(var j = 0;j<citys.length;j++){
                            if(citys[j].name.includes(keyword)){
                                arr.push(citys[j])
                                
                            }
                        }
                    }
                this.value='';
                console.log(arr)
                }
                arr = [];
            }
        }
    </script>
</body>
</html>